import 'package:flutter/material.dart';
import 'package:shopping_group/modle/good/bloc/order_details_bloc.dart';
import 'package:shopping_group/modle/good/entity/shop_order4app_show_entity.dart';
import 'package:shopping_group/res/colors.dart';
import 'package:shopping_group/res/dimens.dart';
import 'package:shopping_group/utils/object_util.dart';
import 'package:shopping_group/utils/utils.dart';
import 'package:shopping_group/utils/widget_utils.dart';

class GoodDetailsPage extends StatefulWidget {
  final String id;
  GoodDetailsPage({Key key, @required this.id}) : super(key: key);

  @override
  _GoodDetailsPageState createState() => _GoodDetailsPageState();
}

class _GoodDetailsPageState extends State<GoodDetailsPage> {
  ShopOrder4AppShowEntity _entity = ShopOrder4AppShowEntity();
  OrderDetailsBloc _bloc;
  @override
  void initState() {
    super.initState();
    _bloc = OrderDetailsBloc();
    _bloc.initDate.add(this.widget.id);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: WidgetUtils.showAppar(context, '订单详情'),
      body: Container(
        height: double.infinity,
        decoration: BoxDecoration(
          color: Colours.title_white,
        ),
        child: SingleChildScrollView(
          scrollDirection: Axis.vertical,
          reverse: false,
          padding: EdgeInsets.all(0.0),
          physics: BouncingScrollPhysics(),
          child: _showView(),
        ),
      ),
    );
  }

  Widget _showView() {
    return StreamBuilder(
      stream: _bloc.sendData,
      initialData: _entity,
      builder: (BuildContext contexts, AsyncSnapshot<Object> snapshot) {
        Object object = snapshot.data;
        if (object is ShopOrder4AppShowEntity) {
          _entity = object;
        }
        return Container(
          decoration: new BoxDecoration(
            color: Colors.white,
          ),
          child: Column(
            children: <Widget>[
              _addressView(),
              WidgetUtils.drawCodeDivider(height: 4),
              _shoppingView(),
              WidgetUtils.drawCodeDivider(height: 4),
              _priceInfoView(),
              WidgetUtils.drawCodeDivider(height: 4),
              _orderInfoView(),
              WidgetUtils.drawCodeDivider(height: 4),
              _orderLogisticsView(),
              WidgetUtils.drawCodeDivider(height: 4),
              _recipientView(),
            ],
          ),
        );
      },
    );
  }

  //订单信息
  Widget _orderInfoView() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        SizedBox(
          height: 16,
        ),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 16),
          child: WidgetUtils.getTextColorView(
            '订单信息',
            Colours.text_2222,
            Dimens.FONT_SIZE_18,
          ),
        ),
        SizedBox(
          height: 16,
        ),
        WidgetUtils.drawCodeDivider(height: 1),
        WidgetUtils.itmeStyleView('订单编号', Utils.reTextNull(_entity.id),
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isShowText: true,
            isShow: false,
            isExpanded: false,
            isContentExpanded: true,
            bewteenleft: 8,
            verticalPadding: 16),
        WidgetUtils.itmeStyleView('下单时间', Utils.reTextNull(_entity.createDate),
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isExpanded: false,
            bewteenleft: 8,
            verticalPadding: 16),
        WidgetUtils.itmeStyleView('支付方式', _entity.payOptionName,
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isExpanded: false,
            bewteenleft: 8,
            verticalPadding: 16),
        WidgetUtils.itmeStyleView('支付时间', _entity.createDate,
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isExpanded: false,
            bewteenleft: 8,
            verticalPadding: 16),
      ],
    );
  }

  //价格信息
  Widget _priceInfoView() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        SizedBox(
          height: 16,
        ),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 16),
          child: WidgetUtils.getTextColorView(
            '价格信息',
            Colours.text_2222,
            Dimens.FONT_SIZE_18,
          ),
        ),
        SizedBox(
          height: 16,
        ),
        WidgetUtils.drawCodeDivider(height: 1),
        WidgetUtils.itmeStyleView(
          '商品价格',
          '¥${_entity.shopPrice}',
          textSize: Dimens.FONT_SIZE_14,
          textColor: Colours.text_2222,
          contentColor: Colours.themeColor,
          contentAlignment: Alignment.centerRight,
        ),
        WidgetUtils.itmeStyleView(
          '规格',
          _entity.optsDetail,
          textSize: Dimens.FONT_SIZE_14,
          textColor: Colours.text_2222,
          contentColor: Colours.themeColor,
          contentAlignment: Alignment.centerRight,
        ),
        WidgetUtils.itmeStyleView(
          '数量',
          '${_entity.shopCt}',
          textSize: Dimens.FONT_SIZE_14,
          textColor: Colours.text_2222,
          contentColor: Colours.themeColor,
          contentAlignment: Alignment.centerRight,
        ),
        WidgetUtils.itmeStyleView(
          '实付款',
          '¥${_entity.shopAllPrice}',
          textSize: Dimens.FONT_SIZE_14,
          textColor: Colours.text_2222,
          contentColor: Colours.themeColor,
          contentAlignment: Alignment.centerRight,
        ),
      ],
    );
  }

  //商品信息
  Widget _shoppingView() {
    return Container(
      decoration: BoxDecoration(
        color: Colours.title_white,
      ),
      padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 8),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Container(
              height: 110.0,
              width: 110.0,
              child: FadeInImage.assetNetwork(
                image: ObjectUtil.isEmptyList(_entity.lstImgUrl) ? '' : _entity.lstImgUrl[0],
                placeholder: 'images/picture_loading.png' /* 指定gif */,
                fit: BoxFit.contain,
              ),
            ),
            flex: 2,
          ),
          Expanded(
            child: Padding(
              padding: const EdgeInsets.only(left: 16),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  WidgetUtils.getTextColorView(
                    _entity.name,
                    Colours.text_2222,
                    Dimens.FONT_SIZE_14,
                  ),
                  SizedBox(
                    height: Dimens.FONT_SIZE_16,
                  ),
                  WidgetUtils.getTextColorView(
                    '¥${Utils.reTextNull(_entity.shopPrice)}/件',
                    Colours.text_2222,
                    Dimens.FONT_SIZE_14,
                  ),
                ],
              ),
            ),
            flex: 3,
          ),
        ],
      ),
    );
  }

  //地址详情
  Widget _addressView() {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              WidgetUtils.getTextColorView(
                '${Utils.reTextNull(_entity.getGoodsManName)}',
                Colours.text_2222,
                Dimens.FONT_SIZE_18,
              ),
              SizedBox(
                width: 32,
              ),
              WidgetUtils.getTextColorView(
                '${Utils.reTextNull(_entity.getGoodsManPhone)}',
                Colours.text_2222,
                Dimens.FONT_SIZE_18,
              ),
            ],
          ),
          SizedBox(
            height: 16,
          ),
          WidgetUtils.getTextColorView(
            '${Utils.reTextNull(_entity.address)}',
            Colours.gray_91,
            Dimens.FONT_SIZE_16,
          ),
        ],
      ),
    );
  }

  //物流详情
  Widget _orderLogisticsView() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        SizedBox(
          height: 16,
        ),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 16),
          child: WidgetUtils.getTextColorView(
            '物流信息',
            Colours.text_2222,
            Dimens.FONT_SIZE_18,
          ),
        ),
        SizedBox(
          height: 16,
        ),
        WidgetUtils.drawCodeDivider(height: 1),
        WidgetUtils.itmeStyleView('订单状态', Utils.reTextNull(_entity.hadSendName),
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isExpanded: false,
            bewteenleft: 8,
            verticalPadding: 16),
        WidgetUtils.itmeStyleView('物流公司', Utils.reTextNull(_entity.kuaiDiTypeName),
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isExpanded: false,
            bewteenleft: 8,
            verticalPadding: 16),
        WidgetUtils.itmeStyleView('物流单号', Utils.reTextNull(_entity.kuaiDiNo ?? ""),
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isShowText: true,
            isShow: false,
            isExpanded: false,
            isContentExpanded: true,
            bewteenleft: 8,
            verticalPadding: 16),
      ],
    );
  }

  //收件人信息
  Widget _recipientView() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        SizedBox(
          height: 16,
        ),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 16),
          child: WidgetUtils.getTextColorView(
            '收件人信息',
            Colours.text_2222,
            Dimens.FONT_SIZE_18,
          ),
        ),
        SizedBox(
          height: 16,
        ),
        WidgetUtils.drawCodeDivider(height: 1),
        WidgetUtils.itmeStyleView('收件人姓名', Utils.reTextNull(_entity.getGoodsManName),
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isExpanded: false,
            bewteenleft: 8,
            verticalPadding: 16),
        WidgetUtils.itmeStyleView('收件人电话', Utils.reTextNull(_entity.getGoodsManPhone ?? ""),
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isShowText: true,
            isShow: false,
            isExpanded: false,
            isContentExpanded: true,
            bewteenleft: 8,
            verticalPadding: 16),
        WidgetUtils.itmeStyleView('收件人区县',
            "${Utils.reTextNull(_entity.provName)}-${Utils.reTextNull(_entity.cityName)}-${Utils.reTextNull(_entity.townName)}",
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isExpanded: false,
            bewteenleft: 8,
            verticalPadding: 16),
        WidgetUtils.itmeStyleView('收件人地址', Utils.reTextNull(_entity.address),
            textSize: Dimens.FONT_SIZE_14,
            contentColor: Colours.text_91,
            isExpanded: true,
            bewteenleft: 8,
            titleExpanded: 0,
            verticalPadding: 16),
      ],
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
